package com.briup.jz.service.impl;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.BaseRolePrivilege;
import com.briup.jz.bean.BaseRolePrivilegeExample;
import com.briup.jz.bean.extend.BaseRolePrivilegeExtend;
import com.briup.jz.dao.extend.BaseRolePrivilegeExtendMapper;
import com.briup.jz.dao.BaseRolePrivilegeMapper;
import com.briup.jz.service.BaseRolePrivilegeService;
import com.briup.jz.utils.CustomerException;

@Service
public class BaseRolePrivilegeServiceImpl implements BaseRolePrivilegeService {

	@Autowired
	private BaseRolePrivilegeMapper baseRolePrivilegeMapper;
	@Autowired
	private BaseRolePrivilegeExtendMapper baseRolePrivilegeExtendMapper;
	@Override
	public void saveOrUpdate(BaseRolePrivilege baseRolePrivilege) throws CustomerException {
		// TODO Auto-generated method stub
		if(baseRolePrivilege.getId()!=null) {
			baseRolePrivilegeMapper.updateByPrimaryKey(baseRolePrivilege);
		} else {
			baseRolePrivilegeMapper.insert(baseRolePrivilege);
		}
	}

	//根据角色id查询角色权限
	@Override
	public List<BaseRolePrivilege> query(Long Id) {
		// TODO Auto-generated method stub
		BaseRolePrivilegeExample example = new BaseRolePrivilegeExample();
		if(Id!=null){
			example.createCriteria().andIdEqualTo((long)Id);
		}
		List<BaseRolePrivilege> list = baseRolePrivilegeMapper.selectByExample(example);
		return list;
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		// TODO Auto-generated method stub
		BaseRolePrivilege baseRolePrivilege = baseRolePrivilegeMapper.selectByPrimaryKey(id);
		if(baseRolePrivilege == null) {
			throw new CustomerException("要删除的分类信息不存在");
		}
		baseRolePrivilegeMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<BaseRolePrivilegeExtend> queryCascade(Long privilegeId) {
		// TODO Auto-generated method stub
		return baseRolePrivilegeExtendMapper.select(privilegeId);
	}

}
